﻿
@{
    ViewData["Title"] = "Login";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section header{
    <link rel="stylesheet" href="~/css/login.css">
}

<body class="login-bg">

    <div class="login layui-anim layui-anim-up">
        <div class="message">管理登录</div>
        <div id="darkbannerwrap"></div>

        <form class="layui-form">
            <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
            <hr class="hr15">
            <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
            <hr class="hr15">
            <button class="layui-btn login_btn" lay-submit="" style="width:100%;" lay-filter="login">登录</button>
            <hr class="hr20">
        </form>
    </div>

    <script>
        layui.use(['layer', 'form'], function () {
            var form = layui.form;
            $("[function='close']").click(function () {
                common.closeOpen();
            });

            //自定义验证规则
            form.verify({
                username: function (value) {
                    if (value.length < 1) {
                        return '请输入用户名！';
                    }
                },
                password: function (value) {
                    if (value.length < 1) {
                        return '请输入密码！';
                    }
                }
            });

            form.on('submit(login)', function (data) {
                var promptLayer = common.reloadMsg("正在登录");
               
                request.ajax({
                    type: "post",
                    url: "/Login/Login",
                    data: {
                        loginName: data.field.username,
                        loginPwd: data.field.password
                    },
                    success: function (result) {
                        common.closeMsg(promptLayer);
                        if (result.success) {
                            sessionStorage.token = result.data.token;
                            window.location.href = "/Admin/Index";
                        } else {
                            common.errorMsg(result.message);
                        }
                    }
                });

                return false;
            });
        });
    </script>

</body>